<template>
  <div id="message">
  	<div class="title">
      消息中心
      <span class="total">（共<span class="number"> {{messageList.length || 0}} </span>条）</span>
    </div>
    <div class="content">
      <div v-if="messageList.length == 0">
        <div class="bgImg"></div>
      </div>
      <div class="message-container" v-for="(messageInfo, index) in messageList" :key="index" v-else>
        <message :message="messageInfo"></message>
      </div>
    </div>
    <w-paging :total="totalPage" :current="pageIndex" @on-page="onPageChange" v-if="totalPage > 1"></w-paging>
  </div>
</template>

<script>
  import Message from './components/Message'
  import { apiOrderAll } from 'js/api'

  export default {
    data() {
      return {
        messageList: [],
        pageIndex: 1,
        totalPage: 1
      }
    },
    created() {
      this.fetchPushMessage(this.pageIndex)
    },
    methods: {
      fetchPushMessage(pageIndex) {
        apiOrderAll(this.$store.getters.token, pageIndex, '').then((data) => {
          this.messageList = data.orderFormList || []
          this.totalPage = data.totalPageCount || 1
        })
      },
      onPageChange(index) {
        this.pageIndex = index
        this.fetchPushMessage(this.pageIndex)
      }
    },
    components: {
      Message
    }
  }
</script>

<style lang="scss" scoped>
  .bgImg {
    background-image: url(../../assets/nullIcon/icon_null.png);
    margin: 50px auto auto;
    width: 310px;
    height: 270px;
    background-repeat: no-repeat;
    text-align: center;
    background-size: contain;
    background-position: 50% 50%;
  }
  #message {
    background-color: #FFFFFF;
    padding: 28px 26px;

    .title {
      font-size: 14px;
      color: #666666;

      .total {
        font-size: 12px;
        color: #999999;
        margin-left: 10px;

        .number {
          color: #F00384;
        }
      }
    }

    .content {
      margin-top: 18px;

      .message-container {
        margin-top: -1px;
      }
    }

    .m-paging {
      margin-top: 40px;
    }
  }
</style>